﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
	<head>
	<base href="<%=basePath%>">
	<!-- jsp文件头和头部 -->
	<%@ include file="../../system/main/main_top.jsp"%> 
	</head> 
<body>
<div id="centerOfMainFrame" style="margin: 10px;10px;10px;10px;">
			<form action="<%=basePath%>tableMenu/addTableMenu.do" name="tableMenuForm" id="tableMenuForm" method="post">
				<input type="hidden" name="currentselecttableconstantsid" id="currentselecttableconstantsid" value="${pageData.currentselecttableconstantsid }"/>
				<input type="hidden" name="org_id" id="org_id" value="${pageData.org_id }"/>
				<input type="hidden" name="exist_product_ids" id="exist_product_ids" value="${exist_product_ids }"/>
				<input type="hidden" name="productids" id="productids"/>
			</form>
			<table id="table_report" class="table table-striped table-bordered table-hover">
				<thead>
					<tr>
						<th class="center">
							<label><input type="checkbox" id="zcheckbox" /><span class="lbl"></span></label>
						</th>
						<th>序号</th>
						<th>商品名称</th>
						<th>商品货号</th>
						<th>库存数量</th>
						<th>商品品牌</th>
						<th>商品类型</th>
						<th><i class="icon-time hidden-phone"></i>优惠开始时间</th>
						<th><i class="icon-time hidden-phone"></i>优惠结束时间</th>
						<th><i class="icon-time hidden-phone"></i>商品有效期</th>
						<th>商品缩略图</th>
						<th>商品状态</th>
					</tr>
				</thead>
										
				<tbody>
				<!-- 开始循环 -->	
				<c:choose>
					<c:when test="${not empty varList}">
						<c:forEach items="${varList}" var="var" varStatus="vs">
							<tr>
								<td class='center' style="width: 30px;">
									<label><input type='checkbox' name='ids' onclick="verifyExistProductId('${var.product_id }');" value="${var.product_id }" id="choose_${var.product_id }" alt="${user.product_name }"/><span class="lbl"></span></label>
								</td>
								<td class='center' style="width: 30px;">${vs.index+1}</td>
								<td>${var.product_name}</td>
								<td>${var.product_sn }</td>
								<td>${var.store_number }</td>
								<td>${var.brandName }</td>
								<td>${var.catName }</td>
								<td><fmt:formatDate value="${var.promote_start_time}" pattern="yyyy-MM-dd"/> </td>
								<td><fmt:formatDate value="${var.promote_end_time}" pattern="yyyy-MM-dd"/> </td>
								<td><fmt:formatDate value="${var.valid_time}" pattern="yyyy-MM-dd"/> </td>
								<td>
									<c:if test="${var.img_thumb != '' && var.img_thumb != null }">
										<a href="<%=basePath%>${var.img_thumb}" target="_blank"><img src="<%=basePath%>${var.img_thumb}" width="50"/></a>
									</c:if>
								</td>
								<td>
									<c:if test="${var.is_on_sale == '0' }"><span class="label label-important arrowed-in">未上架</span></c:if>
									<c:if test="${var.is_on_sale == '1' }"><span class="label label-success arrowed">已上架</span></c:if>
								</td>
							</tr>
						</c:forEach>
						
						<!-- <tr>
							<td colspan="100" class="center">您无权查看</td>
						</tr> -->
					</c:when>
					<c:otherwise>
						<tr class="main_info">
							<td colspan="100" class="center" >没有相关数据</td>
						</tr>
					</c:otherwise>
				</c:choose>
				</tbody>
			</table>
			
		<div class="page-header position-relative">
			<table style="width:100%;">
				<tr>
					<td style="vertical-align:top;">
						<a title="批量提交" class="btn btn-small btn-success" onclick="makeAll('确定要提交选中的数据吗?');" >提交</a>
					</td>
					<td style="vertical-align:top;"><div class="pagination" style="float: right;padding-top: 0px;margin-top: 0px;">${page.pageStr}</div></td>
				</tr>
			</table>
		</div>
	</div>
	<!-- PAGE CONTENT ENDS HERE -->
  	<input type="hidden" name="token" value="${token}" />
	<div id="centerOfMainFrame2" class="center" style="display:none"><br/><br/><br/><br/><img src="static/images/jiazai.gif" /><br/><h4 class="lighter block green"></h4></div>
		<!-- 引入 -->
		<script type="text/javascript">window.jQuery || document.write("<script src='static/js/jquery-1.9.1.min.js'>\x3C/script>");</script>
		<script type="text/javascript" src="static/js/bootstrap.min.js"></script>
		<script type="text/javascript" src="static/js/ace-elements.min.js"></script>
		<script type="text/javascript" src="static/js/ace.min.js"></script>
		<script type="text/javascript" src="static/js/chosen.jquery.min.js"></script><!-- 单选框 -->
		<script type="text/javascript" src="static/js/bootstrap-datepicker.min.js"></script><!-- 日期框 -->
		<script type="text/javascript" src="static/js/bootbox.min.js"></script><!-- 确认窗口 -->
		<!-- 引入 -->
		
		<script type="text/javascript">
		$(top.hangge());
		
		function verifyExistProductId(chooseProductId){
			var exist_product_ids = $("#exist_product_ids").val();
			var array1= new Array();   
			array1 = exist_product_ids.split("-");
			//alert(array1);
		   	for (i = 0; i < array1.length; i++ )   
		    {   
		       if(chooseProductId == array1[i]){
		    	   alert("此商品在菜单中已存在，无需重复添加！");
		    	   document.getElementById('choose_' + chooseProductId).checked = false;
		       }
		    }   
			    
			//var choose = document.getElementById('choose_' + chooseProductId).checked;
			//alert(chooseProductId + " ===== " + exist_product_ids + " choose= " + choose);
		}
		
		//批量操作
		function makeAll(msg){
			bootbox.confirm(msg, function(result) {
				if(result) {
					var str = '';
					var emstr = '';
					var phones = '';
					for(var i=0;i < document.getElementsByName('ids').length;i++)
					{
						  if(document.getElementsByName('ids')[i].checked){
						  	if(str=='') str += document.getElementsByName('ids')[i].value;
						  	else str += ',' + document.getElementsByName('ids')[i].value;
						  	
						  	if(emstr=='') emstr += document.getElementsByName('ids')[i].id;
						  	else emstr += ';' + document.getElementsByName('ids')[i].id;
						  	
						  	if(phones=='') phones += document.getElementsByName('ids')[i].alt;
						  	else phones += ';' + document.getElementsByName('ids')[i].alt;
						  }
					}
					if(str==''){
						bootbox.dialog("您没有选择任何内容!", 
							[
							  {
								"label" : "关闭",
								"class" : "btn-small btn-success",
								"callback": function() {
									//Example.show("great success");
									}
								}
							 ]
						);
						
						$("#zcheckbox").tips({
							side:3,
				            msg:'点这里全选',
				            bg:'#AE81FF',
				            time:8
				        });
						
						return;
					}else{
						if(msg == '确定要提交选中的数据吗?'){
							var currentselecttableconstantsid = $("#currentselecttableconstantsid").val();
							//alert($("#currentselecttableconstantsid").val());
							//alert(str);
							$("#productids").val(str);
							//alert("productids: " + $("#productids").val());
							$("#tableMenuForm").submit();
							$("#centerOfMainFrame").hide();
							$("#centerOfMainFrame2").show();
							return true;
						}
					}
				}
			});
		}
		</script>
		<script type="text/javascript">
		$(function() {
			//单选框
			$(".chzn-select").chosen(); 
			$(".chzn-select-deselect").chosen({allow_single_deselect:true}); 
			//日期框
			$('.date-picker').datepicker();
			
			//复选框
			$('table th input:checkbox').on('click' , function(){
				var that = this;
				$(this).closest('table').find('tr > td:first-child input:checkbox')
				.each(function(){
					this.checked = that.checked;
					$(this).closest('tr').toggleClass('selected');
				});
					
			});
		});
		</script>
	</body>
</html>

